package com.amit.jdbc.mysql;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
import java.util.Scanner;


public class Lab6 {

	
	public static void main(String[] args) throws Exception {
		
		Connection con=null;
		
		try
		{
			
			//1.load the driver class
			Class.forName("com.mysql.jdbc.Driver");
			//Class.forName("oracle.jdbc.diver.OracleDriver");
			
			
			//2.create the connection
			
			 con=DriverManager.getConnection("jdbc:mysql://localhost:3306/amit007","root","root");
			//con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","amit");
			
			//3.create the sql query
			
			Scanner sc=new Scanner(System.in);
			System.out.println("Enter Id");
			int id=sc.nextInt();
			sc.nextLine();
			
			System.out.println("Enter name");
			String name=sc.nextLine();
			

			System.out.println("Enter email");
			String email=sc.nextLine();
			
			System.out.println("Enter Phone");
			long phone=sc.nextLong();
			
//			
//			System.out.println("Enter fee");
//	        float fee=sc.nextFloat();
//	        
//	        System.out.println("Enter dob");
//			int dob=sc.nextInt();
			
String qry=String.format("insert into amit123 values(%d,'%s','%s',%d)",id,name,email,phone);
			System.out.println(qry);

			//4 create the jdbc statement

       Statement st=con.createStatement();
       
       //5.submit the jdbc statement
       
       int i=st.executeUpdate(qry);
       
       if(i==1)
       {
    	   System.out.println("record inserted");
       }
			
       else
       {
    	   System.out.println("No record found found");
       }
		}
		
		catch (Exception e) {
			con.close();
			
			e.printStackTrace();
			
		}
		
		
	}

}
